package com.zjw.remotecall.factory;

import com.google.gson.Gson;

/**
 * @author ：zhong.jw
 * @date ：Created in 2023/8/18 9:31
 */
public class DefaultSerializeFactory implements SerializeFactory {

    private final Gson gson = new Gson();

    @Override
    public byte[] writeToByte(Object o) {
        return gson.toJson(o).getBytes(java.nio.charset.StandardCharsets.UTF_8);
    }

    @Override
    public Object readToObject(byte[] bytes, Class<?> clazz) {
        return gson.fromJson(new String(bytes), clazz);
    }
}
